#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QUdpSocket>
#include <QHostAddress>
#include <QStandardItemModel>
#include <QMap>
#include "type.h"

namespace Ui {
    class Widget;
}

class Widget : public QWidget
{
    Q_OBJECT

public:
    explicit Widget(QWidget *parent = 0);
    ~Widget();

protected:
    void initTreeView();
    bool resolv_dgram(QHostAddress host, const QByteArray *dgram);
    void resolv_cpu(QHostAddress host,const QByteArray *dgram);
    void resolv_mem(QHostAddress host,const QByteArray *dgram);
    void resolv_traffic(QHostAddress host,const QByteArray *dgram);
    void pushCpuData(t_cpuinfo &cpuinfo);
    void pushMemData(t_meminfo &meminfo);
    void pushTrafficData(t_traffic_info &traffic);

private:
    Ui::Widget *ui;
    QUdpSocket *udpSocket;
    QStandardItemModel *model;
    QMap <quint32,t_host_perform*> host_map;
    quint32 current_host;

    void initUdpServer(int port);

private slots:
    void on_hostList_doubleClicked(QModelIndex index);
//    读取数据包槽
    void readPendingDatagrams();
};

#endif // WIDGET_H
